/*
* Description: 基于etw的应用使用统计
*/
#ifndef APP_USING_STATISTICS_H
#define APP_USING_STATISTICS_H
#include "app_using_report.h"
#include <windows.h>
#include <atomic>
#include <direct.h>
#include <evntrace.h>
#include <evntcons.h>
#include <memory>
#include "singleton.h"
#include <unordered_map>
#include <functional>

namespace DFX {
class AppUsingStatistics {
public:
    AppUsingStatistics();
    ~AppUsingStatistics();
    void Init();
    void Quit();
    bool BuildTraceConfig();
    bool BuildTraceController(bool isRetry);
    bool ConsumeTrace();
    void CloseTrace();
private:
    static void ProcessRecordEventsCallback(PEVENT_RECORD pEventRecord);
    static std::atomic_bool isTraceClosed;
    PEVENT_TRACE_PROPERTIES pConfig{ nullptr };
    TRACEHANDLE hTrace{ 0 };
};

#define APP_USING_STATISTICS SingletonNew<DFX::AppUsingStatistics>::GetInstance()
}  // namespace DFX
#endif